<?php
/**
 * 基础资料模块-产品
 */
class Base_ProductController extends Controller_NeedLogin {
	/**
	 * 产品修改日志列表
	 * @return [type] [description]
	 */
	public function modificationLogListAction($field = "*") {
		$goodsSn = $this->getRequest()->getParam('goods_sn');
		if (!$goodsSn) {
			throw new Exception("请指定产品编码！");
		}
		$modifyColumn = $this->getRequest()->getParam('modify_column');
		$updateUser = $this->getRequest()->getParam('update_user');

		$getData = $this->getRequest()->getParams();
		$params = array();

		$params['page'] = $this->getRequest()->getParam('page') ?? 1;
		$params['perPage'] = $this->page_size;

		$db = Model_Db::getInstance();
		$where = " product_log.goods_sn=:goodsSn";
		$bindValue = ['goodsSn' => $goodsSn];
		if ($modifyColumn) {
			$where .= ' and which_col = :modifyColumn';
			$bindValue['which_col'] = $modifyColumn;
		}
		if ($updateUser) {
			$where .= ' and updateUser=：updateUser';
			$bindValue['update_user'] = $updateUser;
		}

		$sql = "select %fields% from product_modify_log as product_log left join p_product_purchase as product_purchase on  product_log.goods_sn=product_purchase.goods_sn  where" . $where;
		$countSql = str_replace("%fields%", 'count(*)', $sql);
		$count = $db->fetchOne($countSql, $bindValue);

		$limit = " limit " . ($params['page'] - 1) * $params['perPage'] . "," . $params['perPage'];
		$fields = "product_log.*,product_purchase.*";
		$querySql = str_replace("%fields%", $fields, $sql) . " order by product_log.id desc " . $limit;
		$list = $db->fetchAll($querySql, $bindValue);

		$pageLink = "";
		if (!empty($list)) {
			$pageLink = $this->page($count, $this->page_size);
		}

		$this->smarty->assign('pageLink', $pageLink);
		$this->smarty->assign('logList', $list);
		$this->smarty->display('productModifyLog.tpl');
	}
}